package com.sanji.sjmallmodule.goods;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sanji.sjmallapp.R;
import com.sanji.sjmallmanager.datamanager.SelectDataManager;
import com.sanji.sjmallwidget.XListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/****
 * 配件fragment
 *****/
public class GoodsPartsFrament extends BaseFrament implements View.OnClickListener, XListView.IXListViewListener, GoodsPartsAdapter.buyGoodsPartsNumberListener {
    @BindView(R.id.fragment_goods_parts_list_view)
    XListView goodsPartsListView;
    private List<GoodsPartsItemBean> mData;
    private GoodsPartsAdapter adapter;
    private int buyTotalNumber;//购买的总数量
    private float buyAccount;//购买的总价格

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_goods_parts, null);
        ButterKnife.bind(this, view);

        initView();
        requestData();
        return view;
    }

    public void initView() {
        mData = new ArrayList<>();
        adapter = new GoodsPartsAdapter(mData, getActivity());
        goodsPartsListView.setAdapter(adapter);
        adapter.setOnBuyGoodsPartsNumberListener(this);
        goodsPartsListView.setXListViewListener(this);
        goodsPartsListView.setPullLoadEnable(false);
        goodsPartsListView.setFooterDividersEnabled(false);
        goodsPartsListView.setHeaderDividersEnabled(false);
    }

    @Override
    public void onClick(View view) {

    }

    //实现懒加载
    @Override
    public void lazyLoadData() {

    }

    /**
     *
     */
    public void requestData() {
        int categoryId = getArguments().getInt("categoryId");
        //模拟数据
        List<GoodsPartsItemBean> partsList = new ArrayList<>();
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484186902&di=563094f98761632b0dc44659d00af648&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F26%2F51%2F68bOOOPIC83_1024.jpg",
//                "￥199", "手机壳", 1, 1));
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484187020&di=ac4912ed59621aa43092547b9556e602&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F23%2F41%2F80bOOOPIC57_1024.jpg",
//                "￥199", "手机壳", 1, 1));
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484186902&di=563094f98761632b0dc44659d00af648&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F26%2F51%2F68bOOOPIC83_1024.jpg",
//                "￥199", "手机壳", 1, 1));
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484187020&di=ac4912ed59621aa43092547b9556e602&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F23%2F41%2F80bOOOPIC57_1024.jpg",
//                "￥199", "手机壳", 1, 1));
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484187020&di=ac4912ed59621aa43092547b9556e602&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F23%2F41%2F80bOOOPIC57_1024.jpg",
//                "￥199", "手机壳", 1, 2));
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484187020&di=ac4912ed59621aa43092547b9556e602&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F23%2F41%2F80bOOOPIC57_1024.jpg",
//                "￥199", "手机壳", 1, 2));
//        partsList.add(new GoodsPartsItemBean("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1484187020&di=ac4912ed59621aa43092547b9556e602&imgtype=jpg&er=1&src=http%3A%2F%2Fpic2.ooopic.com%2F12%2F23%2F41%2F80bOOOPIC57_1024.jpg",
//                "￥199", "手机壳", 1, 2));

        mData.addAll(SelectDataManager.getGoodsPartsByCategory(partsList, categoryId));
        adapter.notifyAdapter(mData);
    }

    //上拉刷新
    @Override
    public void onRefresh() {

    }

    @Override
    public void onLoadMore() {

    }

    @Override
    public void buyGoodsPartsNumber(GoodsPartsItemBean goodsBean) {

    }
    /**
     * 计算商品购买数量和购买总价格
     */
    public void getBuyNumberAndAcount() {

    }
}
